﻿/*
Copyright (C) 2009  Tomasz Chrzanowski

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>
*/

using System;

namespace Com.TomCdc.ChangeDataCapture
{
    /// <summary>
    /// Contains basic column information, the name and indexes of 3 types of data
    /// </summary>
    public struct ColumnMeta
    {
        /// <summary>
        /// The column name.
        /// </summary>
        public string colName;

        /// <summary>
        /// The index of column, containing change state info (whether data has changed).
        /// </summary>
        public int diffColIdx;

        /// <summary>
        /// The index of column, containing old value.
        /// </summary>
        public int delColIdx;

        /// <summary>
        /// The index of column, containing new value.
        /// </summary>
        public int insColIdx;

        /// <summary>
        /// The structure constructor.
        /// </summary>
        /// <param name="diffIdx">Change state column index</param>
        /// <param name="delIdx">Old value column index.</param>
        /// <param name="insIdx">New value column index.</param>
        /// <param name="name">Column name</param>
        public ColumnMeta(int diffIdx, int delIdx, int insIdx, string name)
        {
            // validates input arguments
            if (diffIdx < 1)
            {
                throw new ArgumentOutOfRangeException("The diffIdx argument must be grater than 0");
            }

            if (delIdx < 1)
            {
                throw new ArgumentOutOfRangeException("The delIdx argument must be grater than 0");
            }

            if (insIdx < 1)
            {
                throw new ArgumentOutOfRangeException("The insIdx argument must be grater than 0");
            }

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("The name argument cannot be null or empty.");
            }

            colName = name;
            diffColIdx = diffIdx;
            delColIdx = delIdx;
            insColIdx = insIdx;
        }
    }


}
